package com.aiolos.springboot.stepbystep.quartz;

import com.aiolos.springboot.stepbystep.mail.ISendMailService;
import com.aiolos.springboot.stepbystep.model.AyUser;
import com.aiolos.springboot.stepbystep.service.IAyUserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时器
 */
//@Configuration
//@Component
//@EnableScheduling
public class SendMailQuartz {

    private static final Logger logger = LogManager.getLogger(SendMailQuartz.class);

    @Resource
    private ISendMailService sendMailService;

    @Resource
    private IAyUserService ayUserService;

    //每5秒执行一次
    //@Scheduled(cron = "*/5 * * * * *")
    public void reportCurrentByCron(){
        logger.info("定时器运行了!!!");
        List<AyUser> ayUserList = ayUserService.findAll();
        if(ayUserList == null || ayUserList.size()<=0) return;
        //发送邮件
        sendMailService.sendMail(ayUserList);
    }


}
